home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-04-19 | 2.3 KB | 51 lines | [TEXT/GEOL] |
- Item 9680192 19-April-89 10:21
-
- From: BIANCHI1 Bianchi, Curt
-
- To: ROLLIN1 Rollin, Keith A.
- D2215 Dac SW, Wilma Blair, PRT
-
- cc: MACAPP.TECH$ MACAPP Tech
-
- Sub: Re- Re- Segmentation changes?
-
- Keith, (and Les),
-
- I think what Les is getting at is that if you know a procedure call will not
- affect the heap, then you can pass a field of an object safely, knowing the
- object will not move. In the case of TStaticText.SetText, it's in a
- non-resident segment. Thus a segment load is possible, which may shuffle the
- heap and invalidate the address of an object field passed to SetText. So you
- have to copy the string from the object to a local variable and pass the local
- variable to SetText.
-
- Note that there are some very subtle issues here (and somebody correct me if I
- get this wrong). The string passed to SetText is passed by value. Since it's
- a data structure longer than four bytes, the Pascal compiler actually passes
- the address of the string to SetText. The compiler generates code IN SetText
- to copy the string onto the stack. This means that if calling SetText causes a
- segment load and you pass a field of an object as the string, the address of
- the string could become invalid BEFORE SetText has a chance to copy it. So
- putting SetText in a resident segment would allow you to safely pass a string
- in an object.
-
- Suppose the string in SetText was a VAR parameter. In that case putting
- SetText in a resident segment wouldn't help. If you look at the code in
- SetText you will find that it performs operations that affect the heap. For
- example, it calls the Toolbox routine NewString which allocates a new handle,
- obviously affecting the heap. It also calls other methods which may themselves
- affect the heap or cause segment loads.
-
- Since these issues are tricky you are better off erring on the safe side when
- you're not sure. Errors caused by these mistakes are often difficult to track
- down and may not show up until you run your program in low memory situations or
- with heap scrambling.
-
- In response to Les's original question, could SetText be put in a resident
- segment, I believe things are already frozen for the next APDA release.
- Perhaps it can be done for future release.
-
- Curt Bianchi
- Apple Computer
-
-